using FutureCoreEditor;
using System.IO;
using System.Text;
using UnityEditor;

public static class FileTool
{
    public static void CreateFile(string filePath, string text)
    {
        byte[] textBytes = Encoding.UTF8.GetBytes(text);
        CreateFile(filePath, textBytes);
    }

    public static void CreateEncryptFile(string filePath, string text)
    {
        byte[] textBytes = Encoding.UTF8.GetBytes(text);
        textBytes = XorEncryptUtil.Encrypt(textBytes);
        CreateFile(filePath, textBytes);
    }

    public static void CreateFile(string filePath, byte[] bytes)
    {
        File.WriteAllBytes(filePath, bytes);
    }

    public static void CopyPrefabsToDir(string formDir, string toDir)
    {
        DirectoryTool.ClearDirectory(toDir);
        DirectoryInfo formfolder = new DirectoryInfo(formDir);
        FileSystemInfo[] folders = formfolder.GetFileSystemInfos();
        foreach (FileSystemInfo info in folders)
        {
            if (info is DirectoryInfo)
            {
                FileSystemInfo[] assetFiles = (info as DirectoryInfo).GetFileSystemInfos();
                foreach (FileSystemInfo assetfile in assetFiles)
                {
                    CopyPrefabToDir(assetfile, toDir);
                }
            }
            else
            {
                CopyPrefabToDir(info, toDir);
            }
        }
        AssetDatabase.Refresh();
    }

    public static void CopyPrefabToDir(FileSystemInfo info, string toDir)
    {
        if (!(info is DirectoryInfo) && info.Name.EndsWith(".prefab"))
        {
            File.Copy(info.FullName, toDir + "/" + info.Name, true);
        }
    }
}